package com.turkline.CatchMePolygon;

import java.util.ArrayList;
import java.util.List;

import javax.microedition.khronos.opengles.GL10;

import com.badlogic.androidgames.framework.Game;
import com.badlogic.androidgames.framework.Input.TouchEvent;
import com.badlogic.androidgames.framework.gl.FPSCounter;
import com.badlogic.androidgames.framework.impl.GLGame;
import com.badlogic.androidgames.framework.impl.GLScreen;
import com.badlogic.androidgames.framework.math.OverlapTester;
import com.badlogic.androidgames.framework.math.Vector2;

public class GameScreen extends GLScreen
{
	FPSCounter fpsCounter;
	World world;
	WorldRenderer worldRenderer;
	float stateTime;
	Vector2 touchPoint;
	Help help;
	
	public GameScreen(Game game, int maxSprites, int camWidth, int camHeight, int level)
	{
		super(game, maxSprites, camWidth, camHeight);
		world = new World(Settings.CURRENT_LEVEL, game);
		worldRenderer = new WorldRenderer(glGraphics, batcher, world);
		stateTime = 0;
		touchPoint = new Vector2(0,0);
		
		if(!Settings.firstHelpShowed)
		{
			help = new Help(glGraphics, batcher, game);
		}
	}

	@Override
	public void update(float deltaTime)
	{
		List<TouchEvent> touchEvents = game.getInput().getTouchEvents();
		game.getInput().getKeyEvents();
		TouchEvent event = null;
		for(int i = 0 ; i<touchEvents.size() ; i++)
		{
			event = touchEvents.get(i);
			touchPoint.set(event.x , event.y);
			camera.touchToWorld(touchPoint);
		}
		
		if(!Settings.firstHelpShowed)
		{
			help.update(deltaTime, event);
		}
		else
		{
			world.update(deltaTime , event);
		}
	}

	@Override
	public void present(float deltaTime)
	{
		stateTime+=deltaTime;
		worldRenderer.render(deltaTime);
		if(!Settings.firstHelpShowed)
		{
			help.present(deltaTime);
		}
		if(world.state == World.STATE_GAME_END)
		{
			this.glGame.showAds(true);
		}
		else
		{
			this.glGame.showAds(false);
		}
	}

	@Override
	public void pause()
	{
		// TODO Auto-generated method stub

	}

	@Override
	public void resume()
	{
		// TODO Auto-generated method stub

	}

	@Override
	public void dispose()
	{
		// TODO Auto-generated method stub

	}

}
